package jupiter.channel;

import jupiter.filters.FilterException;
import jupiter.message.*;
import jupiter.util.DBConnection;

import java.sql.SQLException;
import java.util.Hashtable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.json.*;

public class Global {
	static private Hashtable<String, Domain> domainHash = new Hashtable<String, Domain>();
	
	static public void sendMessage(Message m){
		getDomain(m.to() ).sendMessage(m);
	}
	static public Boolean domainPresent(String domainName){
		Domain d = null;
		synchronized(domainHash){
			d = domainHash.get(domainName);
		}
		if(d != null) return true;
		return false;
	}
	static public Domain getDomain(Address a){
		
		Domain d = null;
		String domainName = a.domain();
		synchronized(domainHash){
			d = domainHash.get(domainName);
		}

		
		if(d == null){
			d = new Domain(a);
			synchronized(domainHash){
				domainHash.put(domainName,d );
			}
		}
		return d;
	}
}
